{include file="public/header" /}
<div id="dcWrap">
    <!--包含公共模版-->
    {include file="public/lefter" /}
    <div id="dcMain">
        <!-- 当前位置 -->
        <div id="urHere"><a href="{:url('index/index')}"> 管理中心</a><b>></b><strong>图片列表</strong></div>
        <div class="mainBox" style="height:auto!important;min-height:550px;">
            <h3><a href="{:url('image/add')}" class="actionBtn add">添加图片</a>图片列表</h3>
            <div class="filter">
                <form action="image.php" method="get">
                    <select name="cat_id" id="cat_id">
                        <option value="0">未分类</option>
                        {volist name="category" id="fcat"}
                        <option value="{$fcat.id}" {if condition="$id eq $fcat['id']" }selected{/if}> {$fcat.name}</option>
                        <!--二级分类-->
                        {if condition="isset($fcat.children)"}
                        {volist name="fcat['children']" id="scat"}
                        <option value="{$scat.id}" {if condition="$id eq $scat['id']" }selected{/if}>&nbsp;&nbsp;├&nbsp;&nbsp;{$scat.name}</option>
                            <!--三级分类-->
                            {if condition="isset($scat.children)"}
                            {volist name="scat['children']" id="tcat"}
                            <option value="{$tcat.id}" {if condition="$id eq $tcat['id']" }selected{/if}>&nbsp;&nbsp;&nbsp;&nbsp;├&nbsp;&nbsp;{$tcat.name}</option>
                            {/volist}
                            {/if}
                        {/volist}
                        {/if}
                        {/volist}
                    </select>
                </form>
            </div>
            <div id="list">
                <form name="action" method="post" action="">
                    <table width="100%" border="0" cellpadding="8" cellspacing="0" class="tableBasic">
                        <tr>
                            <th width="22" align="center"><input name='chkall' type='checkbox' id='chkall'
                                                                 onclick='selectcheckbox(this.form)' value='check'></th>
                            <th width="40" align="center">编号</th>
                            <th align="left">名称</th>
                            <th align="center" width="80">点击量</th>
                            <th width="150" align="center">分类</th>
                            <th width="80" align="center">添加日期</th>
                            <th width="250" align="center">操作</th>
                        </tr>
                        {volist name="data" id="vo" empty="$empty"}
                        <tr>
                            <td align="center"><input type="checkbox" name="checkbox[]" value="{$vo.id}"/></td>
                            <td align="center">{$vo.id}</td>
                            <td><a href="{:url('index/show/index',['cid' => $vo.cid,'id' => $vo.id])}" target="_blank">{$vo.title}</a> {if condition="$vo.flag neq 0"}<span class="top-it">{:$image::$flag_desc[$vo.flag]}</span>{/if}</td>
                            <td align="center">{$vo.click}</td>
                            <td align="center"><a href="{:url('image/index',['id' => $vo.cid])}">{$vo.name}</a></td>
                            <td align="center">{$vo.publishtime|date="Y-m-d"}</td>
                            <td align="center">
                            <a href="javascript:;" class="topit btn" data-flag="{$vo.flag}" data-id="{$vo.id}">{if condition="$image::FLAG_TOP == $vo.flag"}取消置顶{else/}置 顶{/if}</a>
                                <a href="{:url('image/edit',['id' => $vo.id])}" class="btn btn-info">编 辑</a>
                                <a class="del btn btn-danger" data-id="{$vo.id}">删 除</a>
                            </td>
                        </tr>
                        {/volist}
                    </table>
                    <div class="action">
                        <select name="action" onchange="douAction()">
                            <option value="0">请选择...</option>
                            <option value="del_all">删除</option>
                            <option value="category_move">移动分类至</option>
                        </select>
                        <select name="new_cat_id" style="display:none">
                            <option value="0">未分类</option>
                            {volist name="category" id="fcat"}
                            <option value="{$fcat.id}"> {$fcat.name}</option>
                            <!--二级分类-->
                            {if condition="isset($fcat.children)"}
                            {volist name="fcat['children']" id="scat"}
                            <option value="{$scat.id}">&nbsp;&nbsp;├&nbsp;&nbsp;{$scat.name}</option>
                                <!--三级分类-->
                                {if condition="isset($scat.children)"}
                                {volist name="scat['children']" id="tcat"}
                                <option value="{$tcat.id}" >&nbsp;&nbsp;&nbsp;&nbsp;├&nbsp;&nbsp;{$tcat.name}</option>
                                {/volist}
                                {/if}
                            {/volist}
                            {/if}
                            {/volist}
                        </select>
                        <span class="execute_btn execute">执行</span>
                    </div>
                </form>
            </div>
            <div class="clear"></div>
            <div class="pager">{$page|raw}</div>
        </div>
    </div>
    <div class="clear"></div>
    {include file="public/footer" /}
    <div class="clear"></div>
</div>
<script type="text/javascript">
var topit_url = "{:url('image/topit')}";
    function douAction() {
        var frm = document.forms['action'];
        frm.elements['new_cat_id'].style.display = frm.elements['action'].value == 'category_move' ? '' : 'none';
    }
    //选择分类展示列表
    $("#cat_id").change(function () {
        var id = $(this).val();
        var url = "{:url('image/index')}" + "?id=" + id;
        window.location.href = url;
    });
    //执行删除 移动分类
    $(".execute").click(function () {
        var action = $("select[name='action']").val();
        var $form = $(this).parents('form');
        if (action == 0) {
            layer.msg('请先选择执行操作');
        } else if (action == 'del_all') {
            confirms('警告','确定要删除吗？','',function(){
                $.get("{:url('image/dele')}",$form.serialize(),function(data){
                    layer.msg(data.msg,function () {
                        location.reload();
                    })
                });
            });
        } else if (action == 'category_move') {
            confirms('警告','确定要移动分类吗？','',function(){
                 var id = $("select[name='new_cat_id']").val();
                if(id == 0){alert('请选择分类');return false;}
                $.get("{:url('image/move')}",$form.serialize(),function(data){
                    layer.msg(data.msg,function () {
                        location.reload();
                    })
                });
            });
        }

    });
   //删除
   $(".del").click(function(){
        var id= $(this).data('id');
        var $this = $(this).parents('tr');
        confirms('','是否确认删除编号为【'+ id +'】？','',function(){
          $.get("{:url('image/dele')}",{id:id},function(data){
               layer.msg(data.msg,{time: 1000}, function(){
                  if (data.status == 1) {
                    $this.remove();
                  }
                });
            },'json');
        }); 
    })
</script>
</body>
</html>
